package inits

import (
	"fmt"
	"github.com/streadway/amqp"
	"log"
	"month/config"
	"month/global"
)

func InitRabbitMQ() {
	AppConf := config.AppConf.RabbitMQ
	//获取connection
	conn, err := amqp.Dial(fmt.Sprintf("amqp://%v:%v@%v/%v", AppConf.Username, AppConf.Password, AppConf.Url, AppConf.Vhost))
	if err != nil {
		panic("Failed to connect to RabbitMQ")
	}
	//获取channel
	global.MQ, err = conn.Channel()

	if err != nil {
		panic("Failed to open a channel")
	}

	log.Println("rabbitMQ 连接成功")

}
